package com.sophic_tech.hkb.controller;

import com.sophic_tech.hkb.entity.ResourceModel;
import com.sophic_tech.hkb.entity.Result;
import com.sophic_tech.hkb.service.resource.GetResourceList;
import com.sophic_tech.hkb.service.resource.Impl.ResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/resource")
public class ResourceController {
    @Autowired
    ResourceService resourceService;
    @GetMapping("/getResourceList")
    public Result getResourceList(@RequestHeader("Authorization") String authHeader) {
        if (authHeader == null || !authHeader.startsWith("Bearer ")) {
            return Result.error(401, "无效的 Authorization 头格式，需以 Bearer 开头");
        }
        String token = authHeader.substring(7).trim();
        return resourceService.getRecommendResourceList(token, 15);
    }
    @PostMapping("/postResource")
    public Result postResource(@RequestHeader("Authorization") String authHeader, @RequestBody ResourceModel resourceModel) {
        if (authHeader == null || !authHeader.startsWith("Bearer ")) {
            return Result.error(401, "无效的 Authorization 头格式，需以 Bearer 开头");
        }
        String token = authHeader.substring(7).trim();
        return resourceService.postResource(token, resourceModel);
    }
}
